package com.ctfo.ulcp.exp.db

import dev.langchain4j.data.document.Document
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader
import dev.langchain4j.data.document.parser.TextDocumentParser
import dev.langchain4j.data.document.parser.apache.pdfbox.ApachePdfBoxDocumentParser
import dev.langchain4j.data.document.parser.apache.poi.ApachePoiDocumentParser

sealed interface ResourceProperty

data class DbProperty(val jdbcUrl: String, val user: String, val password: String, val dbType: DataSourceType) :
    ResourceProperty

data class DocProperty(val url: String, val ext: FileExt, val size: Int) : ResourceProperty

fun DocProperty.loadDocument(): Document? {
    if (size == 0) {
        return null
    }
    val parser = when (ext) {
        FileExt.DOC, FileExt.DOCX -> ApachePoiDocumentParser()
        FileExt.PDF -> ApachePdfBoxDocumentParser()
        FileExt.TXT -> TextDocumentParser()
    }
    // 为了便于测试,这里使用文件系统加载
    return FileSystemDocumentLoader.loadDocument(url, parser)
}


data class InterfaceProperty(
    val url: String,
    val method: String,
    val contentType: String,
    val reqSummary: String,
    val respSummary: String
) : ResourceProperty

fun main() {
//    val jdbcUrl = "jdbc:mysql://172.20.60.19:3306/ctfo_trunk_assistant?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai"
    val jdbcUrl =
        "jdbc:mysql://172.20.60.19:3306/ctfo_platform_system?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai"

    val db = DbProperty(jdbcUrl, "root", "123456", DataSourceType.MySQL)
//    db.genTextSegments()
}



